# view.py

from PySide6.QtWidgets import (QApplication, QMainWindow, QVBoxLayout, QHBoxLayout, 
                               QPushButton, QLabel, QMenuBar, QMenu, QGroupBox, 
                               QWidget, QTextEdit, QGridLayout, QSpacerItem, QSizePolicy)
from PySide6.QtGui import QIcon, QAction

from PySide6.QtCore import Qt

class MainWindow(QMainWindow):
    def __init__(self, controller):
        super().__init__()
        self.controller = controller
        self.setWindowTitle("Main Window")
        self.setGeometry(100, 100, 300, 200)

        self.init_ui()

    def init_ui(self):
        # 菜单栏
        menubar = self.menuBar()
        file_menu = menubar.addMenu('文件')
        help_menu = menubar.addMenu('帮助')

        exit_action = QAction('退出', self)
        exit_action.triggered.connect(self.close)
        file_menu.addAction(exit_action)

        about_action = QAction('关于', self)
        about_action.triggered.connect(lambda: print("关于"))
        help_menu.addAction(about_action)

        theme_action = QAction('主题', self)
        theme_action.triggered.connect(lambda: print("主题"))
        help_menu.addAction(theme_action)

        # 主布局
        main_layout = QVBoxLayout()

        # AD Group Box
        ad_group_box = QGroupBox("AD")
        ad_layout = QGridLayout()
        ad_icon = QLabel()
        ad_icon.setFixedSize(50, 50)
        ad_icon.setAlignment(Qt.AlignCenter)
        ad_icon.setText("图标")
        ad_layout.addWidget(ad_icon, 0, 0)
        ad_label = QLabel("运行")
        ad_label.setAlignment(Qt.AlignCenter)
        ad_layout.addWidget(ad_label, 1, 0)
        ad_group_box.setLayout(ad_layout)
        ad_group_box.mousePressEvent = self.controller.show_time_window

        # 功能 Group Box
        func_group_box = QGroupBox("功能")
        func_layout = QVBoxLayout()
        func_layout.addItem(QSpacerItem(0, 0, QSizePolicy.Minimum, QSizePolicy.Expanding))
        func_group_box.setLayout(func_layout)

        main_layout.addWidget(ad_group_box)
        main_layout.addWidget(func_group_box)

        central_widget = QWidget()
        central_widget.setLayout(main_layout)
        self.setCentralWidget(central_widget)

class TimeWindow(QWidget):
    def __init__(self, controller):
        super().__init__()
        self.controller = controller
        self.setWindowTitle("Time Window")
        self.setGeometry(300, 300, 300, 200)

        self.init_ui()

    def init_ui(self):
        layout = QVBoxLayout()

        self.time_label = QLabel("00:00:00")
        self.time_label.setAlignment(Qt.AlignCenter)
        layout.addWidget(self.time_label)

        self.pause_button = QPushButton("暂停")
        self.pause_button.clicked.connect(self.controller.toggle_time_display)
        layout.addWidget(self.pause_button)

        self.exit_button = QPushButton("退出")
        self.exit_button.clicked.connect(self.close)
        layout.addWidget(self.exit_button)

        self.setLayout(layout)